"""
该文件用于 扫描界面
"""
import time

from utils.utils_log import loggerCase
from page.base_page import BasePage
from common_ai_img import AIButton, Icon, OcrText

class ScanPage(BasePage):
    """扫描页面"""

    # 预扫按钮
    __preview_button = AIButton(Icon("preview scan"))

    # 扫描按钮
    __scan_button = AIButton(Icon("start scan"))

    # 扫描暂停按钮
    __pause_button = AIButton(Icon("pause scan"))

    # 优化框架点
    __global_markers_optimization = AIButton(Icon("global markers optimize"))

    # 删除数据按钮
    __delete_button = AIButton(Icon("delete"))

    # 扫描框架点模式
    __scan_global_marker = AIButton(OcrText("Scan Global Markers"))

    # 摄影测量
    __photogrammetry = AIButton(OcrText("photogrammetry"))

    # 扫描网格模式
    __scan_mesh = AIButton(OcrText("Scan Mesh"))

    # 局部分辨率模式
    __partial_resolution = AIButton(OcrText("Partial Resolution"))

    # 扫孔模式
    __ai_feature_recognition = AIButton(OcrText("AI Feature Recognition"))

    # 交叉线
    __cross_line = AIButton(Icon("cross line"))

    # 平行线
    __parallel_line = AIButton(Icon("parallel line"))

    # 单线
    __single_line = AIButton(Icon("single line"))

    # 普通模型
    __normal_button = AIButton(Icon("normal"))

    # 反光模式
    __reflective_button = AIButton(Icon("reflective"))

    # 户外模式关
    __outdoor_mode_off = AIButton(Icon("outdoor mode_off"))

    # 户外模式开
    __outdoor_mode_on = AIButton(Icon("outdoor mode_on"))

    # 模型质量色谱关
    __data_quality_indicator_off = AIButton(Icon("data quality indicator_off"))

    # 模型质量色谱开
    __data_quality_indicator_on = AIButton(Icon("data quality indicator_on"))

    # 扫描点云关
    __scan_in_point_cloud_off = AIButton(Icon("scan in point cloud_off"))

    # 扫描点云开
    __scan_in_point_cloud_on = AIButton(Icon("scan in point cloud_on"))

    # 局部放大关
    local_enlarged_view_off = AIButton(Icon("local enlarged view_off"))

    # 局部放大开
    local_enlarged_view_on = AIButton(Icon("local enlarged view_on"))

    # 视角锁定关
    view_lock_off = AIButton(Icon("view lock_off"))

    # 视角锁定关
    view_lock_on = AIButton(Icon("view lock_on"))

    # 智能分辨率关
    intelligent_resolution_off = AIButton(Icon("intelligent resolution_off"))

    # 智能分辨率开
    intelligent_resolution_on = AIButton(Icon("intelligent resolution_on"))

    def judge_exist_preview_button(self):
        return self.judge_element_exist(ScanPage.__preview_button, max_wait_time=3, is_end=False, is_need_screen=False,
                                    max_retries=1)


    def click_preview_scan_button(self, max_wait_time=3):
        """预扫"""
        loggerCase.info("点击预扫按钮")
        self.click(ScanPage.__preview_button, max_wait_time=max_wait_time)

    def click_scan_button(self, max_wait_time=20):
        """开始扫描"""
        loggerCase.info("点击开始扫描按钮")
        self.click(ScanPage.__scan_button, max_wait_time=max_wait_time)

    def click_pause_button(self, max_wait_time=3):
        """扫描暂停"""
        loggerCase.info("点击暂停按钮")
        self.click(ScanPage.__pause_button, max_wait_time=max_wait_time)
        self.loading()

    def click_global_markers_optimization(self, max_wait_time=3):
        """优化框架点"""
        loggerCase.info("点击优化框架点按钮")
        self.click(ScanPage.__global_markers_optimization, max_wait_time=max_wait_time)
        self.loading()

    def click_delete_button(self, max_wait_time=3):
        """清除数据"""
        loggerCase.info("点击清除数据按钮")
        self.click(ScanPage.__delete_button, max_wait_time=max_wait_time)


    def click_scan_global_marker(self, max_wait_time=3):
        """扫描框架点"""
        loggerCase.info("点击扫描框架点按钮")
        self.click(ScanPage.__scan_global_marker, max_wait_time=max_wait_time)

    def click_photogrammetry(self, max_wait_time=3):
        """摄影测量"""
        loggerCase.info("点击摄影测量按钮")
        self.click(ScanPage.__photogrammetry, max_wait_time=max_wait_time)

    def click_scan_mesh(self, max_wait_time=3):
        """扫描网格"""
        loggerCase.info("点击扫描网格按钮")
        self.click(ScanPage.__scan_mesh, max_wait_time=max_wait_time)
        self.loading()

    def click_partial_resolution(self, max_wait_time=3):
        """局部分辨率"""
        loggerCase.info("点击局部分辨率按钮")
        self.click(ScanPage.__partial_resolution, max_wait_time=max_wait_time)

    def click_ai_feature_recognition(self, max_wait_time=3):
        """扫孔"""
        loggerCase.info("点击扫孔按钮")
        self.click(ScanPage.__ai_feature_recognition, max_wait_time=max_wait_time)

    def click_cross_line_button(self, max_wait_time=3):
        """交叉线"""
        loggerCase.info("点击交叉线按钮")
        self.click(ScanPage.__cross_line, max_wait_time=max_wait_time)

    def click_parallel_line(self, max_wait_time=3):
        """平行线"""
        loggerCase.info("点击平行线按钮")
        self.click(ScanPage.__parallel_line, max_wait_time=max_wait_time)

    def click_single_line(self, max_wait_time=3):
        """单线"""
        loggerCase.info("点击单线按钮")
        self.click(ScanPage.__single_line, max_wait_time=max_wait_time)

    def click_normal_button(self, max_wait_time=3):
        """普通模式"""
        loggerCase.info("点击普通模式")
        self.click(ScanPage.__normal_button, max_wait_time=max_wait_time)

    def click_reflective_button(self, max_wait_time=3):
        """反光模式"""
        loggerCase.info("点击反光模式按钮")
        self.click(ScanPage.__reflective_button, max_wait_time=max_wait_time)

    def click_outdoor_mode_checkbox(self, status, max_wait_time=3):
        """户外模式"""
        loggerCase.info(f"点击户外模式：{status}")
        if status == 'off':
            if self.judge_element_exist(ScanPage.__outdoor_mode_on, max_wait_time = max_wait_time, is_end=False,is_need_screen=False,max_retries=1):
                self.click(ScanPage.__outdoor_mode_on, max_wait_time=max_wait_time)
            else:
                loggerCase.info("户外模式开关无需点击")
        elif status == 'on':
            if self.judge_element_exist(ScanPage.__outdoor_mode_off, max_wait_time=max_wait_time, is_end=False,
                                        is_need_screen=False, max_retries=1):
                self.click(ScanPage.__outdoor_mode_off, max_wait_time=max_wait_time)
                time.sleep(2)
                self.click(AIButton(OcrText("Got it")))
            else:
                loggerCase.info("户外模式开关无需点击")

    def click_data_quality_indicator_checkbox(self, status, max_wait_time=3):
        """模型质量色谱"""
        loggerCase.info(f"点击模型质量色谱：{status}")
        if status == 'off':
            if self.judge_element_exist(ScanPage.__data_quality_indicator_on, max_wait_time=max_wait_time, is_end=False,
                                        is_need_screen=False, max_retries=1):
                self.click(ScanPage.__data_quality_indicator_on, max_wait_time=max_wait_time)
            else:
                loggerCase.info("模型质量色谱开关无需点击")
        elif status == 'on':
            if self.judge_element_exist(ScanPage.__data_quality_indicator_off, max_wait_time=max_wait_time, is_end=False,
                                        is_need_screen=False, max_retries=1):
                self.click(ScanPage.__data_quality_indicator_off, max_wait_time=max_wait_time)
            else:
                loggerCase.info("模型质量色谱开关无需点击")


    def click_scan_in_point_cloud_checkbox(self, status, max_wait_time=3):
        """点云模式"""
        loggerCase.info(f"点击点云模式：{status}")
        if status == 'off':
            if self.judge_element_exist(ScanPage.__scan_in_point_cloud_on, max_wait_time=max_wait_time, is_end=False,
                                        is_need_screen=False, max_retries=1):
                self.click(ScanPage.__scan_in_point_cloud_on, max_wait_time=max_wait_time)
            else:
                loggerCase.info("点云模式开关无需点击")
        elif status == 'on':
            if self.judge_element_exist(ScanPage.__scan_in_point_cloud_off, max_wait_time=max_wait_time, is_end=False,
                                        is_need_screen=False, max_retries=1):
                self.click(ScanPage.__scan_in_point_cloud_off, max_wait_time=max_wait_time)
            else:
                loggerCase.info("点云模式开关无需点击")

    def click_local_enlarged_view_checkbox(self, status, max_wait_time=3):
        """局部放大"""
        loggerCase.info(f"点击局部放大：{status}")
        if status == 'off':
            if self.judge_element_exist(ScanPage.local_enlarged_view_on, max_wait_time=max_wait_time, is_end=False,
                                        is_need_screen=False, max_retries=1):
                self.click(ScanPage.local_enlarged_view_on, max_wait_time=max_wait_time)
            else:
                loggerCase.info("局部放大开关无需点击")
        elif status == 'on':
            if self.judge_element_exist(ScanPage.local_enlarged_view_off, max_wait_time=max_wait_time, is_end=False,
                                        is_need_screen=False, max_retries=1):
                self.click(ScanPage.local_enlarged_view_off, max_wait_time=max_wait_time)
            else:
                loggerCase.info("局部放大开关无需点击")

    def click_view_lock_checkbox(self, status, max_wait_time=3):
        """视角锁定"""
        loggerCase.info(f"点击视角锁定：{status}")
        if status == 'off':
            if self.judge_element_exist(ScanPage.view_lock_on, max_wait_time=max_wait_time, is_end=False,
                                        is_need_screen=False, max_retries=1):
                self.click(ScanPage.view_lock_on, max_wait_time=max_wait_time)
            else:
                loggerCase.info("视角锁定开关无需点击")
        elif status == 'on':
            if self.judge_element_exist(ScanPage.view_lock_off, max_wait_time=max_wait_time, is_end=False,
                                        is_need_screen=False, max_retries=1):
                self.click(ScanPage.view_lock_off, max_wait_time=max_wait_time)
            else:
                loggerCase.info("视角锁定开关无需点击")

    def click_intelligent_resolution_checkbox(self, status, max_wait_time=3):
        """智能分辨率"""
        loggerCase.info(f"点击智能分辨率：{status}")
        if status == 'off':
            if self.judge_element_exist(ScanPage.intelligent_resolution_on, max_wait_time=max_wait_time, is_end=False,
                                        is_need_screen=False, max_retries=1):
                self.click(ScanPage.intelligent_resolution_on, max_wait_time=max_wait_time)
            else:
                loggerCase.info("智能分辨率开关无需点击")
        elif status == 'on':
            if self.judge_element_exist(ScanPage.intelligent_resolution_off, max_wait_time=max_wait_time, is_end=False,
                                        is_need_screen=False, max_retries=1):
                self.click(ScanPage.intelligent_resolution_off, max_wait_time=max_wait_time)
            else:
                loggerCase.info("智能分辨率开关无需点击")

if __name__ == '__main__':
    ScanPage().click_scan_in_point_cloud_checkbox("off")